using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using EventAbstractionAPI.RuleEngine;
using System.Diagnostics;

namespace WindowsApplication
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>

    public partial class Window1 : System.Windows.Window
    {

        public Window1()
        {
            InitializeComponent();

            EventLoop c = new EventLoop();
            
	    //This is the same triple Click example from 201 but this time
	    // we want to see what the rule engine is doing.

            c.EventBuffer.WorkFlowStartEvent += new EventHandler(EventBuffer_WorkFlowStartEvent);
            c.EventBuffer.WorkFlowEndEvent += new EventHandler(EventBuffer_WorkFlowEndEvent);

            c.EventBuffer.Register(new SeqEvent(new TimeSpan(0, 0, 0, 4, 0), "TripleClick", "DoubleClick", "Click"));
            c.EventBuffer.Register(new SeqEvent(new TimeSpan(0, 0, 0, 2, 0), "DoubleClick","Click","Click"));
            
        }

        /// <summary>
        /// These are event handlers that can only be used with a version of the
        /// EventAbstractionAPI that is compiled under debug. These methods output diagnostic information to the console
        /// treating code behind the EventAlegebra ie c.EventBuffer as a Black Box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void EventBuffer_WorkFlowEndEvent(object sender, EventArgs e)
        {
            List<ICapturedEvent> items = (List<ICapturedEvent>)sender;

            Debug.WriteLine("-----------End------------");
            foreach (CapturedEvent item in items)
            {
                Debug.WriteLine(item.ComplexName + item.EventName);
            }
            Debug.WriteLine("--------------------------");
        }

        void EventBuffer_WorkFlowStartEvent(object sender, EventArgs e)
        {
            List<ICapturedEvent> items = (List<ICapturedEvent>)sender;

            Debug.WriteLine("-----------Start----------");
            foreach (CapturedEvent item in items)
            {
                Debug.WriteLine(item.ComplexName + item.EventName);
            }
            Debug.WriteLine("--------------------------");
        }

    }
}